package org.jin.jinaicode;

import dev.langchain4j.community.store.embedding.redis.spring.RedisEmbeddingStoreAutoConfiguration;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import javax.sql.DataSource;

// 如果需要禁用数据库，可以改为 @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@SpringBootApplication(exclude = {RedisEmbeddingStoreAutoConfiguration.class})
@MapperScan("org.jin.jinaicode.mapper")
public class JinAiCodeApplication {

	public static void main(String[] args) {
		SpringApplication.run(JinAiCodeApplication.class, args);
	}

	// 这个Bean只在数据源自动配置开启时才生效
	@Bean
	@ConditionalOnProperty(prefix = "spring.datasource", name = "url")
	public DataSourceTransactionManager transactionManager(DataSource dataSource) {
		return new DataSourceTransactionManager(dataSource);
	}
}
